class ApplicationController < ActionController::Base
  # Pick a unique cookie name to distinguish our session data from others'
  session :session_key => '_roomies_session_id'
  before_filter :check_cookie
  
  def check_cookie
    return if session[:uid]
      if cookies[:logowanie_login]
        @user = User.find_by_username(cookies[:roomies_username])
        return unless @user 
        cookie_hash = Digest::MD5.hexdigest(cookies[:roomies_login_pass] + @user.password_salt)
        if @user.cookie_hash == cookie_hash
	  flash[:info] = 'You\'ve been automatically logged in' # annoying msg
          session[:uid] = @user.id
          redirect_to :controller => "home"
        else 
          flash[:error] = 'Something is wrong with your cookie'
        end
      end
  end
  
end

